package org.jflame.context.filemanager;

import org.jflame.commons.util.NumberHelper;
import org.jflame.commons.util.StringHelper;

import java.util.Map;

/**
 * 生成预签名url的请求参数
 *
 * @author charles.zhang
 */
public class PresignedUrlArgs {

    /**
     * 默认签名有效期30分钟
     */
    protected static int DEFAULT_EXPIRE_TIME = 30 * 60;
    /**
     * 允许上传的单个文件最大值,单位字节
     */
    private long maxFileSize = 0;
    /**
     * 文件保存路径
     */
    private String savePath;
    /**
     * 文件名或扩展名(扩展名以.开头)
     */
    private String fileNameOrExt;
    /**
     * 上传预签名url有效期,单位秒
     */
    private Integer expireTime = DEFAULT_EXPIRE_TIME;

    private Map<String, String> headers;
    private Map<String, String> queryParams;
    private Map<String, String> userMetadata;

    public PresignedUrlArgs(String fileNameOrExt) {
        this(null, fileNameOrExt, null);
    }

    public PresignedUrlArgs(String fileNameOrExt, Integer expireTime) {
        this(null, fileNameOrExt, expireTime);
    }

    public PresignedUrlArgs(String savePath, String fileNameOrExt, Integer expireTime) {
        this(savePath, fileNameOrExt, expireTime, 0);
    }

    public PresignedUrlArgs(String savePath, String fileNameOrExt, Integer expireTime, long maxFileSize) {
        StringHelper.requireNonEmpty(fileNameOrExt, "fileNameOrExt must not be empty");
        this.fileNameOrExt = fileNameOrExt;
        this.savePath = savePath;
        if (NumberHelper.gtZero(expireTime)) {
            this.expireTime = expireTime;
        }
        if (maxFileSize > 0) {
            this.maxFileSize = maxFileSize;
        }
    }

    public long getMaxFileSize() {
        return maxFileSize;
    }

    public void setMaxFileSize(long maxFileSize) {
        this.maxFileSize = maxFileSize;
    }

    public String getSavePath() {
        return savePath;
    }

    public void setSavePath(String savePath) {
        this.savePath = savePath;
    }

    public String getFileNameOrExt() {
        return fileNameOrExt;
    }

    public void setFileNameOrExt(String fileNameOrExt) {
        this.fileNameOrExt = fileNameOrExt;
    }

    public Integer getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Integer expireTime) {
        this.expireTime = expireTime;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public Map<String, String> getQueryParams() {
        return queryParams;
    }

    public void setQueryParams(Map<String, String> queryParams) {
        this.queryParams = queryParams;
    }

    public Map<String, String> getUserMetadata() {
        return userMetadata;
    }

    public void setUserMetadata(Map<String, String> userMetadata) {
        this.userMetadata = userMetadata;
    }

}
